# -*- coding: utf-8 -*-
# @Organization  : asiainfo
# @Author        : 周伟东
# @Time          : 2021/1/7 11:49
# @Function      : config 配置模块
import logging
import os

from app.constants import CONFIG_NAME

APP_DIR = os.path.dirname(__file__)


class Config:
    # 设置日志等级
    LOG_LEVEL = logging.DEBUG
    MYSQL = {
        'host': '192.168.1.223',  # 换成你自己的ip地址
        'port': 3306,  # 换成你自己的端口号，以下也一样
        'username': 'root',
        'password': '1qazXSW@3edc',
        'database': 'SSA'
    }
    SERVER = {
        "host": "0.0.0.0",  # 服务ip地址
        "port": 19999,  # 服务监听端口
        "debug": True
    }

    KAFKA_PRODUCER = {
        "bootstrap_servers": "KAFKA0:9092",  # kafka的地址
        "kafka_topic": "cyberspace-test"
    }


def get_config(section, option):
    try:
        config = config_dict[CONFIG_NAME]
        return getattr(config, section)[option]
    except AttributeError:
        logging.error('section {0} 不存在!'.format(section))
    except KeyError:
        logging.error('option {0} 不存在!'.format(option))


def get_section(section):
    try:
        config = config_dict[CONFIG_NAME]
        return getattr(config, section)
    except AttributeError:
        logging.error('section {0} 不存在!'.format(section))


class DevelopConfig(Config):
    ENV = 'develop'


class ProductConfig(Config):
    ENV = 'product'
    SERVER = {
        "host": "0.0.0.0",  # 服务ip地址
        "port": 8099,  # 服务监听端口
        "debug": False
    }


class TestConfig(Config):
    ENV = 'test'


config_dict = {
    'develop': DevelopConfig,
    'product': ProductConfig,
    'test': TestConfig,
    'default': DevelopConfig
}
